<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> js面向对象编程 </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 </head>

 <body>
  <script>
	(function() {
		//构造函数
		var Task =  function(nums) {
			this.nums = nums;
		};
		//原型函数
		Task.prototype.square = function() {
			var squares = [];
			for (var i = 0; i < this.nums.length; i++) {
				squares.push(this.nums[i] * this.nums[i]);
			}
			return squares;
		};
		//原型函数
		Task.prototype.sum = function(arr) {
			var res = 0;
			for (var i = 0; i < arr.length; i++) {
				res += arr[i];
			}
			return res;
		};

		var t = new Task([2, 4, 6]);
		console.log(t.sum(t.square()));//56

	})();
  </script>
 </body>
</html>
